import GCGlobal from "../GCGlobal";
import GCResponse from "../network/GCResponse";

export class AccountResponse extends GCResponse {
    name: string;
    icon: string;

    token: string;

    hearts: number;

    survivalCount: number;

    parseResponse(payload: any): void {
        this.token = payload.token;

        this.name = payload.name;

        this.icon = payload.icon;
        this.hearts = payload.hearts;
        this.survivalCount = payload.survivalCount;
    }
}

export class DailyResponse extends GCResponse {
    hearts: number;

    parseResponse(payload: any): void {
        this.hearts = payload.hearts;
    }
}

export interface ILeaderboardItem {
    rank: number;
    name: string;
    hearts: number;
    icon: string;
    isMe: number;//0否，1是
}

export class LeaderboardResponse extends GCResponse {
    list: ILeaderboardItem[] = [];

    me: ILeaderboardItem = null;

    parseResponse(payload: any): void {
        const list = payload.list;
        const me = payload.me;

        if (!list || !list.length) {
            this.list.length = 0;
            return;
        }

        for (let i = 0, len = list.length; i < len; i++) {
            const raw = list[i];

            this.list.push(raw);
        }

        this.me = me;
    }
}


export class TipResponse extends GCResponse {
    tip: string;

    parseResponse(payload: any): void {
        this.tip = payload.tip;
    }
}
